import {ReturnValueHandler} from "../../server/web/_ReturnValueHandler"
import {Component} from "../../server/support/anno/Component"

const ejs = require("ejs")


@Component()
class RenderHandler extends ReturnValueHandler {
  canWrite(value: any): boolean {
    return typeof value === "string"
  }

  write(req: HttpRequest, res: HttpResponse, value: any): void {
    const file = res.getStaticResource("/index.ejs")
    const html = ejs.renderFile(file, {name: value}, (err, str) => {
      res.end(str)
    })
  }

}
